package com.csnf.jtz.dao.impl;

import com.csnf.jtz.dao.StudentDao;
import com.csnf.jtz.entity.Student;
import com.csnf.jtz.util.JdbcUtil;

import java.util.List;
import java.util.Objects;

public class StudentDaolmpl implements StudentDao {

    @Override
    public Boolean addStudent(Student student) {
        System.out.println(student);
        // id自动生成，state 状态 默认为1
        String sql = "INSERT INTO student(id,name,gender,birthday,clazz,state) VALUES(null,?,?,?,?,'1')";
        return JdbcUtil.updateTable(sql, student.getName(), student.getGender(), student.getBirthday(), student.getClazz());
    }

    @Override
    public Student getStudentById(Integer id) {
        String sql = "SELECT * FROM studer WHERE id = ?";
        return Objects.requireNonNull(JdbcUtil.queryTable(Student.class, sql, id)).get(0);
    }

    @Override
    public List<Student> getAll(){
        String sql ="select * from student";
        return JdbcUtil.queryTable(Student.class,sql);
    }
}
